package com.another.bidservice.service.impl;

import com.another.bidservice.entity.TPlanBidder;
import com.another.bidservice.dao.jpa.PlanBidderJPADao;
import com.another.bidservice.dao.mapper.PlanBidderDao;
import com.another.bidservice.service.IPlanBidderService;
import com.another.common.utils.common.EmptyUtil;
import com.another.common.utils.common.MyException;
import com.another.common.utils.result.Result;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
@Service
@Transactional
public class PlanBidderServiceImpl extends BaseServiceImpl implements IPlanBidderService {

    private Logger logger=Logger.getLogger(this.getClass());
    
    @Autowired
    private PlanBidderDao planbidderDao;
    
    @Autowired
    private PlanBidderJPADao planbidderJPADao;
    
    @Override
    public Result getList(TPlanBidder tPlanBidder) {
        String sql="select * from db_sys.vt_plan_bidder";
        List<TPlanBidder> list=planbidderDao.getList(sql);
        if (EmptyUtil.isEmpty(list)) {
            return Result.success("没有查询到数据！", "");
        } else {
            return Result.success(list);
        }
    }

    
    @Override
    public Result insertList(List<TPlanBidder> tPlanBidders) {
        int ret = planbidderDao.insertList(tPlanBidders);
        if(ret==tPlanBidders.size()){
            return Result.success("添加成功！","");
        }else{
            throw new MyException(101, "添加失败！");
        }
    }

    
    @Override
    public Result deleteList(List<Integer> rowid) {
        int ret = planbidderDao.deleteList(rowid);
        if(ret==rowid.size()){
            return Result.success("删除成功！","");
        }else{
            throw new MyException(101, "删除失败！");
        }
    }
    
    @Override
    public Result updateList(List<TPlanBidder> tPlanBidders) {
        try {
            int ret = planbidderDao.updateList(tPlanBidders);
            return Result.success("修改成功！","");
        }catch (Exception e){
            logger.info(e.getMessage(),e);
            throw new MyException(101, "修改失败！");
        }
    }
    
    
    @Override
    public Result insertPlanBidder(TPlanBidder tPlanBidder) {
        try {
            int ret = planbidderDao.insertPlanBidder(tPlanBidder);
            return Result.success("添加成功！", "");
        } catch (Exception e) {
            logger.info(e.getMessage(),e);
            throw new MyException(101, "添加失败！");
        }
    }

    @Override
    public Result updatePlanBidder(TPlanBidder tPlanBidder) {
        try {
            int ret = planbidderDao.updatePlanBidder(tPlanBidder);
            return Result.success("修改成功！", "");
        } catch (Exception e) {
            logger.info(e.getMessage(),e);
            throw new MyException(101, "修改失败！");
        }
    }

    @Override
    public Result deletePlanBidder(TPlanBidder tPlanBidder) {
        try {
            int ret = planbidderDao.deletePlanBidder(tPlanBidder);
            return Result.success("删除成功！", "");
        } catch (Exception e) {
            logger.info(e.getMessage(),e);
            throw new MyException(101, "删除失败！");
        }
    }
}



